<template>
  <a-drawer
    :title="title"
    :maskClosable="true"
    width="650"
    placement="right"
    :closable="true"
    @close="close"
    :visible="visible"
    style="overflow: auto; padding-bottom: 53px"
  >
    <div style="display: flex">
      <div style="width: 45%; height: 700px; border: 1px solid red">
        <a-tree
          v-model="selectedKeys"
          checkable
          :selected-keys="defaultSelectedKeys"
          :tree-data="treeData" 
          :show-line="true"
          :default-expand-all="defaultExpandAll"
        />
      </div>
      

    </div>

    <div class="drawer-bootom-button">
      <a-popconfirm title="确定放弃编辑？" @confirm="handleCancel" okText="确定" cancelText="取消">
        <a-button style="margin-right: 0.8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleSubmit" type="primary" :loading="confirmLoading">提交</a-button>
    </div>
  </a-drawer>
</template>
<script>
import { putAction, getFileAccessHttpUrl, getAction } from '@/api/manage'

export default {
  name: 'PermissionModal',
  components: {},
  data() {
    return {
      title: '用户权限配置',
      visible: false,
      userId: '',
      defaultExpandAll: true,
      selectedKeys: [],
      defaultSelectedKeys: [],
      treeData: [],
      confirmLoading: false,
      url: {
        getTreeByUserId: '/upms/user/getTreeByUserId'
      }
    }
  },
  methods: {
    handleSubmit() {
      
    },
    handleCancel() {
      this.close()
    },
    show(userId) {
      this.userId = userId
      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    loadData() {
      getAction(this.url.getTreeByUserId,{id:this.userId,type:1}).then(res=>{
        if(res.code==200){
          this.treeData=res.result.data;
          this.defaultSelectedKeys=res.result.permissions;
        }else{
          this.$message.warning('加载已有用户权限失败')
        }
      })
    },
  },
  watch: {
    visible() {
      if (this.visible) {
        this.loadData()
      }
    }
  },
}
</script>
<style lang="less" scoped>
.drawer-bootom-button {
  position: absolute;
  bottom: 0;
  width: 100%;
  border-top: 1px solid #e8e8e8;
  padding: 10px 16px;
  text-align: right;
  left: 0;
  background: #fff;
  border-radius: 0 0 2px 2px;
}
</style>